var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  n = require("../../../@babel/runtime/helpers/slicedToArray"),
  i = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../../components/base/m-button/index"),
  d = require("../../../config/index"),
  o = require("../../../utils/index"),
  u = e(require("../behavior")),
  s = o.helper.publish;

function c(e) {
  return l.apply(this, arguments)
}

function l() {
  return (l = i(r().mark((function e(t) {
    var i, a, d, o, u, c, l, m, p, _, h, f, v, g, b, x, k, y, q, w, C, I;
    return r().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return i = this.data.mode, e.next = 3, $.request["GET/business/for/rent/detail/".concat(t)]();
        case 3:
          a = e.sent, d = n(a, 1), 20002 === (o = d[0]).code ? (u = o.data, c = u.phone, l = u.description, m = u.mfg, p = u.workTerm, _ = u.rent, h = u.brand_id, f = u.model_id, v = u.class_id, g = u.place, b = u.provinceId, x = u.cityId, k = u.latitude, y = u.longitude, q = u.rent_unit, w = u.coverImageUrlList ? u.coverImageUrlList : [], C = {
            address: g,
            city_id: x,
            city_text: u.cityText,
            latitude: k,
            longitude: y,
            province_id: b,
            province_text: u.provinceText
          }, console.log(C), I = w.map((function (e, index) {
            return {
              url: e,
              fileId: u.coverImageIdList[index]
            }
          })), this.selectComponent("#form").setValues({
            images: I,
            address: C,
            tel: c,
            detail: l,
            manufacture_date: m,
            worked_hour: u.workTerm,
            machine: {
              id: u.modelId,
              name: u.modelName
            },
            brand: h,
            model: f,
            rent_price: _,
            rent_unit: q
          }), this.setData({
            machineValue: {
              id: u.modelId,
              name: u.modelName
            }
          })) : 14004 == o.code ? $.jxAlert({
            mode: "confirm",
            hideClose: !0,
            title: "温馨提示",
            content: o.msg,
            confirmText: "刷新信息"
          }).then((function () {
            s.reqInfoRefresh({
              mode: i,
              info: t
            }, !0)
          })).catch((function () {
            $.router.back()
          })) : $.jxAlert({
            content: o.msg
          });
        case 7:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))).apply(this, arguments)
}
Page({
  useStore: function (e) {
    return {
      userInfo: e.storage.userInfo,
      machineConfig: e.global.machineConfig,
      areaList: e.storage.areaTree
    }
  },
  behaviors: [u.default],
  data: {
    mode: d.typeMode.complain,
    recommendList: [],
    machineValue: null,
    date: "",
    id: "",
    info: ""
  },
  bindDateChange: function (e) {

    this.setData({
      date: e.detail.value
    })
  },
  onLoad: function (e) {
    var t = this;
    this.setData({
      id: e.id
    })
    wx.showLoading({
      title: '加载中...',
    })
    $.request["GET/business/dishonesty/record/detail/".concat(t.data.id)]().then(res => {
      res = res[0]
      if (res.code == 20002) {
        t.setData({
          info: res.data
        })
        t.selectComponent("#form").setValues({
          dishonestyName: res.data.dishonestyName,
          dishonestyPhone: res.data.dishonestyPhone,
          place:res.data.provinceText+res.data.cityText+res.data.place
        })
      } else {
        wx.showToast({
          icon: "none",
          title: res.msg,
        })
      }
    }).finally(()=>{
      wx.hideLoading()
    })
    return i(r().mark((function i() {
      var a, d, o, u, s;
      return r().wrap((function (r) {
        switch (r.prev = r.next) {
          case 0:
            return r.next = 2;
          case 2:
            a = r.sent, t.selectComponent("#form").setValues({
              tel: wx.getStorageSync('userPhone')
            }), (s = e.uu_id) && (t.setData({
              uu_id: s
            }), c.call(t, s));
          case 9:
          case "end":
            return r.stop()
        }
      }), i)
    })))()
  },
  onClickFactoryLabel: function (e) {
    var t = e.target.dataset.item,
      n = this.data.factoryYearsValue,
      a = n && n.id == t.id;
    this.setData({
      factoryYearsValue: a ? null : {
        id: t.id,
        name: t.name
      }
    })
  },
  getDetail(id) {
    c.call(this, id)
  },
  imgview(e){
    console.log(e)
    var imgs = e.target.dataset.imgs
    var index = e.target.dataset.index
    console.log(index)
    wx.previewImage({
      urls: imgs,
      current:imgs[index]
    })
  },
  onSubmit: (0, a.apply)(i(r().mark((function e() {
    var n, i, a, d, o, u, c, l, m, p, _, h, f, v, g, b;
    return r().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return e.next = 5, this.selectComponent("#form").verify({
            dishonestyName: [{
              required: !0,
              message: "请输入黑老板姓名"
            }],
            dishonestyPhone: [{
              required: !0,
              message: "请输入黑老板手机号"
            }],
            address: [{
              required: !0,
              message: "请选择事发地点"
            }, ],
            images: [{
              required: !0,
              message: "请上传证据截图"
            }],
          });
        case 2:
          if (a = e.sent, !this.data.isShowCode || a.code) {
            e.next = 5;
            break
          }
          return e.abrupt("return", void $.msg("请输入验证码"));
        case 5:
          if (a = e.sent, a.detail && !((null === (n = a.detail) || void 0 === n ? void 0 : n.length) < 5)) {
            e.next = 7;
            break
          }
          return e.abrupt("return", void $.msg("举报内容必须大于5个字符"));
        case 7:
          console.log(a)
          $.request['POST/business/dishonesty/record/add']({
            cityId: a.address.city_id,
            cityText: a.address.city_text,
            coverImageIdList: a.images.map((function (e) {
              return e.fileId
            })),
            description: a.detail,
            dishonestyName: a.dishonestyName,
            dishonestyPhone: a.dishonestyPhone,
            place: a.address.address,
            provinceId: a.address.province_id,
            provinceText: a.address.province_text,
            type: this.data.factoryYearsValue.name
          }).then(res => {
            res = res[0]
            if (res.code == 20002) {
              let pages = getCurrentPages()
              let prevpage = pages[pages.length - 2];
              prevpage.onRefresh()
              $.msg("创建成功"), setTimeout((function () {
                $.router.back({
                  params: {
                    "page-type": "publish"
                  }
                })
              }), 2000)
            } else {
              wx.showToast({
                icon: "none",
                title: res.msg,
              })
            }
          })
          e.next = 13;
          break;
        case 13:
          return e.next = 15;
        case 15:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))),
  onShow: function () {
    var e = this;
    return i(r().mark((function t() {
      var i, a, d, u, s, c, l, m, p, _, h, f, v, g, b, x, k, y, q, w, C, I, T, D;
      return r().wrap((function (t) {
        switch (t.prev = t.next) {
          case 0:
            if (null == (i = $.router.getParams()) || !i.uuid) {
              t.next = 8;
              break
            }
            return t.next = 4, console.log(i), $.request["GET/business/for/rent/detail/".concat(null == i ? void 0 : i.uuid)]();
          case 4:
            a = t.sent, d = n(a, 1), 200 === (u = d[0]).code && (l = u.content, m = l.desc, p = l.manufacture_date, _ = l.worked_hour, h = l.rent_price, f = l.brand_id, v = l.model_id, g = l.class_id, b = l.place, x = l.provinceId, k = l.cityId, y = l.latitude, q = l.longitude, w = l.rent_unit, C = l.coverImageUrlList ? coverImageUrlList : [], I = o.tools.common.getTreePathKey(e.data.areaList, k || x), T = {
              address: b,
              city_id: k,
              latitude: y,
              longitude: q,
              province_id: x,
              province_text: (null == I || null === (s = I[0]) || void 0 === s ? void 0 : s.name) || "",
              city_text: (null == I || null === (c = I[1]) || void 0 === c ? void 0 : c.name) || ""
            }, D = C.map((function (e) {
              return {
                url: e.local,
                deliverUrl: e.server
              }
            })), e.selectComponent("#form").setValues({
              images: D,
              address: T,
              detail: l.description,
              manufacture_date: p,
              worked_hour: l.workTerm,
              machine: {
                id: l.modelId,
                name: l.modelName
              },
              brand: f,
              model: v,
              rent_price: l.rent,
              rent_unit: w
            }), e.setData({
              machineValue: {
                id: g[0].id,
                name: g[0].name
              }
            }));
          case 8:
          case "end":
            return t.stop()
        }
      }), t)
    })))()
  },
  onOpenDevice: function () {
    $.router.push("/subpackage/device/list/index", {
      type: "hire"
    })
  }
});